<template>
  <view class="wrap-quest">
    <!-- 任务 -->
    <view v-if="quest.status == 0">
      <!-- 视频 -->
      <MyQuest3Text
          v-if="quest.mode == 2 || quest.mode == 4"
          ref="myQuest3"
          :completeCount="completeCount"
          :quest="quest"
          :sum="sum"
      ></MyQuest3Text>
      <!-- 图片-->
      <MyQuest2Text
          v-if="quest.mode == 1"
          ref="myQuest2"
          :completeCount="completeCount"
          :quest="quest"
          :sum="sum"
      ></MyQuest2Text>
      <!-- 答题 -->
      <MyQuest1Text
          v-if="quest.mode == 3"
          ref="myQuest1"
          :completeCount="completeCount"
          :quest="quest"
          :sum="sum"
      ></MyQuest1Text>
    </view>
    <!-- 剧本 -->
    <zy-quest ref="zQuest" :obj="questObj" @close="onClose"></zy-quest>
    <!-- <view class="btns">
        <image
          class="btn"
          @click="toUrl(`/pages/challenge/learn?scenicId=${scenicId}`)"
          src="https://travel20231111.oss-cn-hangzhou.aliyuncs.com/image/xyx-btn.png"
        ></image>
        <image
          class="btn"
          @click="upload"
          src="https://travel20231111.oss-cn-hangzhou.aliyuncs.com/image/jcsk-btn.png"
        ></image>
      </view>
      <image
        class="xyg-btn"
        @click="onSubmit"
        src="https://travel20231111.oss-cn-hangzhou.aliyuncs.com/image/xyg-btn.png"
      ></image> -->
  </view>
</template>

<script>
import MyQuest1Text from "@/components/quest/quest1Text.vue";
import MyQuest2Text from "@/components/quest/quest2Text.vue";
import MyQuest3Text from "@/components/quest/quest3Text.vue";
import {historyFindOneTask} from "@/api/challenge";

export default {
  data() {
    return {
      key: null, // 任务id
      scenicId: null, // 景点id
      quest: {}, // 当前任务,
      partyId: null, // 团ID
      list: [], // 全部任务
      questObj: {}, // 剧本参数
    };
  },
  components: {
    MyQuest1Text,
    MyQuest2Text,
    MyQuest3Text,
  },
  computed: {
    // 总数
    sum() {
      return this.completeCount + this.umCompleteCount;
    },
  },
  onLoad({partyId, scenicId, key}) {
    this.partyId = partyId;
    this.scenicId = scenicId;
    this.key = key;
    this.getHistoryFindTask(partyId, scenicId, key);
  },
  methods: {
    onClose() {
      this.questObj = null;
      uni.navigateBack({
        delta: 1,
      });
    },
    // 获取景点任务
    getHistoryFindTask(partyId, scenicId, key) {
      historyFindOneTask({
        partyId,
        scenicId,
      }).then((res) => {
        this.completeCount = res.completeCount;
        this.umCompleteCount = res.umCompleteCount;
        this.list = res.scenicTaskDtos.filter((el) => el.status != 2);
        this.quest = res.scenicTaskDtos.filter((el) => el.key == key)[0]; // 正式
        // this.quest = res.scenicTaskDtos.filter((el) => el.scenicTaskId == scenicTaskId && el.mode == 1)[0];
        if (this.quest.status == 1) {
          this.questObj = this.quest;
          // 剧本
          this.$refs.zQuest.show();
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.wrap-quest {
  width: 100%;
  padding-bottom: 100rpx;

  .btns {
    padding: 0 40rpx 20rpx;
    box-sizing: border-box;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .btn {
      width: 300rpx;
      height: 92rpx;
    }
  }

  .xyg-btn {
    width: calc(100% - 80rpx);
    height: 92rpx;
    display: block;
    margin: 0 auto;
  }
}
</style>
